package com.hemaapp.yjnh.activity;

import android.content.Intent;
import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.view.View;
import android.widget.Button;
import android.widget.ImageButton;
import android.widget.TextView;

import com.hemaapp.hm_FrameWork.HemaNetTask;
import com.hemaapp.hm_FrameWork.result.HemaBaseResult;
import com.hemaapp.yjnh.BaseFragmentActivity;
import com.hemaapp.yjnh.R;
import com.hemaapp.yjnh.adapter.TabViewPagerAdapter;
import com.hemaapp.yjnh.fragment.FarmerOrderListFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.Bind;
import butterknife.ButterKnife;
import butterknife.OnClick;

/**
 * 田家的商品订单
 */
public class FarmerOrdersListActivity extends BaseFragmentActivity {

    @Bind(R.id.title_left_btn)
    ImageButton titleLeftBtn;
    @Bind(R.id.title_right_btn)
    Button titleRightBtn;
    @Bind(R.id.title_text)
    TextView titleText;
    @Bind(R.id.layout_tab)
    TabLayout layoutTab;
    @Bind(R.id.viewpager)
    ViewPager viewpager;

    private FarmerOrderListFragment unPayFragment = new FarmerOrderListFragment();
    private FarmerOrderListFragment unDeliveryFragment = new FarmerOrderListFragment();
    private FarmerOrderListFragment unReceiveFragment = new FarmerOrderListFragment();
    private FarmerOrderListFragment sendedFragment = new FarmerOrderListFragment();
    private FarmerOrderListFragment finishFragment = new FarmerOrderListFragment();
    private TabViewPagerAdapter pagerAdapter;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        setContentView(R.layout.activity_custom_orders);
        ButterKnife.bind(this);
        super.onCreate(savedInstanceState);
        initDatas();
    }

    private void initDatas() {
        List<String> titles = new ArrayList<>();
        titles.add("未支付");
        titles.add("待发货");
        titles.add("待收货");
        titles.add("待评价");
        titles.add("已完成");
        unPayFragment.setKeytype("4");
        unDeliveryFragment.setKeytype("2");
        unReceiveFragment.setKeytype("5");
        sendedFragment.setKeytype("7");
        finishFragment.setKeytype("6");
        List<Fragment> fragments = new ArrayList<>();
        fragments.add(unPayFragment);
        fragments.add(unDeliveryFragment);
        fragments.add(unReceiveFragment);
        fragments.add(sendedFragment);
        fragments.add(finishFragment);
        pagerAdapter = new TabViewPagerAdapter(getSupportFragmentManager(), fragments, titles);
        viewpager.setAdapter(pagerAdapter);
        viewpager.setOffscreenPageLimit(4);
        layoutTab.setTabMode(TabLayout.MODE_FIXED);
        layoutTab.setupWithViewPager(viewpager);
        layoutTab.setTabsFromPagerAdapter(pagerAdapter);
    }

    @Override
    protected void findView() {

    }

    @Override
    protected void getExras() {

    }

    @Override
    protected void setListener() {
        titleText.setText("商品订单");
        titleRightBtn.setText("问题订单");
    }

    @Override
    protected void callBeforeDataBack(HemaNetTask hemaNetTask) {

    }

    @Override
    protected void callAfterDataBack(HemaNetTask hemaNetTask) {

    }

    @Override
    protected void callBackForServerSuccess(HemaNetTask hemaNetTask, HemaBaseResult hemaBaseResult) {

    }

    @Override
    protected void callBackForServerFailed(HemaNetTask hemaNetTask, HemaBaseResult hemaBaseResult) {

    }

    @Override
    protected void callBackForGetDataFailed(HemaNetTask hemaNetTask, int i) {

    }

    public void updateTabs(int position, String content) {
        layoutTab.getTabAt(position).setText(content);
    }

    @OnClick({R.id.title_left_btn, R.id.title_right_btn})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_left_btn:
                finish();
                break;
            case R.id.title_right_btn:
                Intent itReturn = new Intent(mContext, FarmerReturnedOrderListActivity.class);
                startActivity(itReturn);
                break;
        }
    }
}
